package com.example.bkzhushi;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.checkbox)
    CheckBox checkbox;
    @BindView(R.id.button)
    Button button;
    @BindView(R.id.text)
    TextView text;
    @BindView(R.id.edit_text)
    EditText editText;
    @BindView(R.id.list_view)
    ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        listView.setAdapter(new myAdepter());
    }

    @OnClick({R.id.checkbox, R.id.button, R.id.text, R.id.edit_text})
    public void onViewClicked(View view) {
        Toast.makeText(MainActivity.this, view.getId() + "", Toast.LENGTH_SHORT).show();
    }

    public class myAdepter extends BaseAdapter {
        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }
        class ViewHolder {
            @BindView(R.id.list_text)
            TextView listText;

            ViewHolder(View view) {
                ButterKnife.bind(this, view);
            }
        }
        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            ViewHolder viewHolder;
            if(view==null) {
                view = LayoutInflater.from(MainActivity.this).inflate(R.layout.layout, viewGroup, false);
                viewHolder = new ViewHolder(view);
                view.setTag(viewHolder);
            }else {
                viewHolder = (ViewHolder) view.getTag();
            }
            viewHolder.listText.setText("sfkjhjjfbj");
            return view;
        }

    }
}
